﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：超级管理员
 * 日  期：2022-03-14 10:58
 * 描  述：业务表
 */
var refreshGirdData;
var selectData = [];
var ProjectIndex = request('ProjectIndex');
var ProjectId = request('ProjectId');
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGird();
            page.bind();
        },
        bind: function () {
            // 查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

            // 保存
            $('#lr_save').on('click', function () {
                if (selectData == null || selectData.length == 0) {
                    learun.alert.warning('请至少选择一个要同步的数据！');
                    return false;
                }
                learun.layerConfirm('数据同步会覆盖已有项目数据，请确认！', function (res) {
                    if (res) {
                        var postData = {
                            strData: JSON.stringify(selectData)
                        }
                        $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_project/SynData?ProjectIndex=' + ProjectIndex + "&ProjectId=" + ProjectId, postData, function (res) {

                        });
                    }
                });
            });
        },
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_business_table/GetPageList',
                headData: [
                    {
                        label: "选择", name: "BusinessTableID", index: "IsCheck", width: 60, align: "center", sort: false, frozen: true,
                        formatter: function (cellvalue, row, op, $cell) {
                            return "<input code='" + row.BusinessTableCode+"' name='my" + row.BusinessTableID + "' type='checkbox' style='cursor: pointer;margin-top: 8px;' onclick='Select(\"" + row.BusinessTableID + "\",\"" + row.BusinessTableCode + "\")'>";
                        }
                    },
                    { label: '业务表名称', name: 'BusinessTableName', width: 250, align: "left", sort: false },
                    { label: '业务表编号', name: 'BusinessTableCode', width: 250, align: "left", sort: false },
                    { label: '', name: '', width: 1, sort: false },
                ],
                mainId: 'BusinessTableID',
                isPage: true,
            });
            page.search();
        },
        search: function (param) {
            param = param || {};
            param.BusinessTableName = $('#BusinessTableName').val();
            param.IsCopyData = 1;
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    page.init();
}
function Select(id,code)
{
    var obj = $('#gridtable').context.getElementsByName("my" + id);
    if (obj && obj.length > 0) {
        if (obj[0].checked) {
            selectData.push(code);
        } else {
            selectData = $.grep(selectData, function (item) {
                return item !== code;
            });
        }
    }
};